<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <button>发起请求</button>
    <h1></h1>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <script>
      const btn = document.querySelector("button");
      const h1 = document.querySelector("h1");
      btn.addEventListener("click", async function () {
        Promise.all([
          myAjax({
            method: "GET",
            url: "http://ajax-base-api-t.itheima.net/api/getbooks",
          }),
          myAjax({
            method: "POST",
            url: "http://ajax-base-api-t.itheima.net/api/addbook",
            data: { bookname: "aaaccc", author: "11cc1", publisher: "accc" },
          }),
        ])
          .then((res) => {
            console.log(res);
            h1.innerHTML = "我是首页";
          })
          .catch((error) => {
            console.log(error);
            h1.innerHTML = error;
          });
      });
    </script>
  </body>
</html>
